package framework.classification.entities.lattice.erca;

import java.util.HashMap;
import java.util.ArrayList;
import java.util.HashMap;
import com.googlecode.erca.clf.Concept;

import framework.classification.entities.ClAbstractEntity;

import com.googlecode.erca.Entity;
import com.googlecode.erca.clf.Concept;


import framework.entity.ACLComponent;
import framework.entity.ACLInterface;
public class LatticeComponentProvided extends LatticeAbstractErca {

	@Override
	public void calculateReduced(ClAbstractEntity table) {
		conceptToExtends = new HashMap<String,ArrayList<String>>();
		realOperations = new HashMap<String, String>();
		abstractOperations = new HashMap<String, String>();
		
		String name = lattice.getName();
		for (int i = 0; i < lattice.getConcepts().size(); i++) {
			Concept concept = lattice.getConcepts().get(i);
			concept.setName("C"
					+ concept.getName().substring(
							concept.getName().indexOf("_") + 1));
			caculateOperationConcept(concept,table);


		}
		
	}
	
	public void caculateOperationConcept(Concept concept,
			ClAbstractEntity table) {
		
		//soit le concept à un extent, dans ce cas il represente une interface deja definis
		if (!concept.getSimplifiedExtent().isEmpty()){
			for (Entity ent : concept.getSimplifiedExtent()){

				ACLComponent aclcompo = new ACLComponent(ent.getName());
				ArrayList<ACLInterface> interspro = table.getAbstractClassfication().getStructure().getComponentsProvided().get(ent.getName());
				ArrayList<ACLInterface> intersreq = table.getAbstractClassfication().getStructure().getComponentsRequired().get(ent.getName());
				for (ACLInterface aclinter : interspro){
					aclcompo.addInterfacePro(aclinter);
				}
				for (ACLInterface aclinter : intersreq){
					aclcompo.addInterfaceReq(aclinter);

				}	
				realOperations.put(aclcompo.toString(),concept.getName());
				
				if (!conceptToExtends.containsKey(concept.getName()))
					conceptToExtends.put(concept.getName(),new ArrayList<String>());
				if (!conceptToExtends.get(concept.getName()).contains(aclcompo.toString()))
					conceptToExtends.get(concept.getName()).add(aclcompo.toString());

				if (lattice.getTop() == concept) superEntity = aclcompo.toString();

				//affichage à enlever
//				System.out.println(aclcompo.getName());
//				for (ACLInterface interreq : aclcompo.getInterfacesReq()){
//					System.out.println("\t"+interreq.getName());
//				}
//				System.out.println("------------------------------------------");
//				for (ACLInterface interpro : aclcompo.getInterfacesPro()){
//					System.out.println("\t"+interpro.getName());
//				}
//				System.out.println();
			}

		}
		//on ne s'interesse pas au concepts abstraits
	
	}
	
	
	public ArrayList<String> getSubstituteElement(String name){
		
		
		return null;
	}
	public ArrayList<String> getSubstituteElement2(String name){
		
		
		return null;
	}
	
	
}
